package controle;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.DataManager;

public class Controle extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	public void init() {
		System.out.println("Init Servlet");
		ServletConfig config = getServletConfig();
		DataManager dataManager = new DataManager();
		
		dataManager.setDbURL(config.getInitParameter("dbURL"));
		dataManager.setDbUserName(config.getInitParameter("dbUserName"));
		dataManager.setDbPassword(config.getInitParameter("dbPassword"));
		
		ServletContext context = config.getServletContext();
		context.setAttribute("init", "true");
		context.setAttribute("dataManager", dataManager);
		
		try {  // load the database JDBC driver
		      Class.forName(config.getInitParameter("jdbcDriver"));
		}
		catch (ClassNotFoundException e) {
		      System.out.println(e.toString());
		}
		    
		
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.sendRedirect("lista.jsp");
	}

}
